﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using Evaluation3.data;
using Evaluation3.classes;
using System.Web.Configuration;
using Evaluation3.utils;

public partial class uicontrol_Chon_SanPham_HoiDong : System.Web.UI.UserControl
{
    OleDbConnection myConnection;
    remoteUser objRemoteUser;
    String MaDoanhNghiep;
    SanPham objSanPham;
    HoiDong objHoiDong;
    protected void Page_Load(object sender, EventArgs e)
    {
        
        String connectinString = WebConfigurationManager.ConnectionStrings["Evaluation"].ConnectionString;
        myConnection = new OleDbConnection(connectinString);
        if (!IsPostBack)
        {
            objRemoteUser = (remoteUser)Session["remoteUser"];
            MaDoanhNghiep = objRemoteUser.companyId;
            //Response.Write(MaDoanhNghiep);
            objSanPham = new SanPham();
            objSanPham.ActiveConnection = myConnection;
            objSanPham.SelectCondition = "MaDoanhNghiep='" + MaDoanhNghiep + "'";
            objSanPham.LoadData();
            cbo_SanPham.DataSource = objSanPham;
            cbo_SanPham.DataTextField = "TenSanPham";
            cbo_SanPham.DataValueField = "MaSanPham";
            cbo_SanPham.DataBind();
            cbo_SanPham.Items.Insert(0, "Chọn một sản phẩm");
        }
    }
    protected void cbo_SanPham_SelectedIndexChanged(object sender, EventArgs e)
    {
        //Response.Write(cbo_SanPham.SelectedValue.ToString());
        objHoiDong = new HoiDong();
        objHoiDong.ActiveConnection = myConnection;
        objHoiDong.SelectCondition = "SanPham.MaSanPham='" + cbo_SanPham.SelectedValue.ToString() + "'";
        objHoiDong.LoadData();
        cbo_HoiDong.DataSource = objHoiDong;
        cbo_HoiDong.DataTextField = "TenHoiDong";
        cbo_HoiDong.DataValueField = "MaHoiDong";
        cbo_HoiDong.DataBind();
        cbo_HoiDong.Items.Insert(0, "Chọn một hội đồng");
    }
    protected void bntChapNhan_Click(object sender, EventArgs e)
    {
        if (cbo_SanPham.SelectedIndex== 0)
        {
            lblSanPham.Text = "Vui lòng chọn sản phẩm!";
            lblSanPham.Visible = true;
            return;
        }
        else
        {
            lblSanPham.Visible = false ;
        }
//        if (cbo_HoiDong.SelectedValue == null || cbo_HoiDong.Text.ToString().Trim().Length == 0)
        if (cbo_HoiDong.SelectedIndex==0)
        {
            lblHoiDong.Text = "Vui lòng chọn hội đồng!";
            lblHoiDong.Visible = true;
            return;
        }
        else
        {

            lblHoiDong.Visible = false;
        }
        Session["MaSanPham"] = cbo_SanPham.SelectedValue;
        Session["MaHoiDong"] = cbo_HoiDong.SelectedValue;
        Response.Redirect("~/webUI/mod/Diem_Chi_Tiet.aspx");
    }
}
